﻿using System;

using SBPweb.Modules.Modularity;

namespace SBPweb.Modules.Communication
{
	/// <summary>
	/// Class of MessageBase
	/// </summary>
    public abstract class MessageBase : IMessage
    {
		/// <summary>
		/// Base format
		/// </summary>
        public static string BASE_FORMAT = "From: {0} - {1}";

        #region Protected fields

		/// <summary>
		/// Text
		/// </summary>
        protected string pText;
		/// <summary>
		/// Format
		/// </summary>
        protected string pFormat = BASE_FORMAT;
		/// <summary>
		/// Sender
		/// </summary>
        protected IModule pSender;

        #endregion

        #region Constructor logic

		/// <summary>
		/// Constructor of MessageBase
		/// </summary>
		/// <param name="sender">sender</param>
		/// <param name="text">text</param>
        protected MessageBase(IModule sender, string text)
        {
            pSender = sender;
            pText = text;
        }

        #endregion

        #region Public property accessors

		/// <summary>
		/// Text
		/// </summary>
        public string Text
        {
            get
            {
                return pText;
            }
        }

		/// <summary>
		/// Format
		/// </summary>
        public string Format
        {
            get
            {
                return pFormat;
            }
            protected set
            {
                pFormat = value;
            }
        }

		/// <summary>
		/// Sender of the message
		/// </summary>
        public IModule Sender
        {
            get
            {
                return pSender;
            }
        }

        #endregion

        #region Methods

		/// <summary>
		/// ToString
		/// </summary>
		/// <returns>string</returns>
        public override string ToString()
        {
            return string.Format(pFormat, pSender.Name, pText);
        }

        #endregion
    }
}